package cn.tede.javagame.shoot;

import javax.swing.*;
import java.awt.*;

public class Enermy {
    //属性
    int x,y;
    int speed;
    int fire,life;
    static Image enemyImag;
    static Image[] enemyImgs = new Image[6];
    //静态代码块
    static{
        enemyImag =  new ImageIcon("pjdz/Pic/flys0.png").getImage();
        for(int i=0;i< enemyImgs.length;i++){
            enemyImgs[i]=new ImageIcon("pjdz/Pic/flys"+i+".png").getImage();
        }
    }
    public Enermy(){
        this.x=(int)(Math.random()*(ShootFrame.WIDTH-enemyImag.getWidth(null)));
        this.y=-enemyImag.getHeight(null);
        this.speed=(int)(Math.random()*2+1);
        this.fire=1;
        this.life=100;
        /*
        int pos;
        this.enemyImag = new ImageIcon("pjdz/Pic/flys0.png").getImage();
        for(int i =0;i<enemyImgs.length;i++){
            enemyImgs[i] = new  ImageIcon("pjdz/Pic/flys"+i+".png").getImage();
        }
        pos=(int)(Math.random()*ShootFrame.WIDTH+enemyImag.getWidth(null));
        if(pos==0){
            this.x=(int)(Math.random()*ShootFrame.WIDTH+enemyImag.getWidth(null));
        }else{
            this.x=(int)(Math.random()*ShootFrame.WIDTH);
        }
        this.y=0;
        this.speed=2;
         */
    }
    //方法
    int index = 0;
    public void move(){
        //this.x=x;
        this.y+=speed;
        /*
        this.y+=speed;
        if(this.y>=ShootFrame.HEIGHT){
            //this.x=(int)(Math.random()*ShootFrame.WIDTH+enemyImag.getWidth(null));
            //此处设置存在漏洞，可能会生成范围外的飞机
            this.x=(int)(Math.random()*ShootFrame.WIDTH+enemyImag.getWidth(null));
            this.y=-enemyImag.getHeight(null);
            this.y+=speed;
        }

         */
    }
    public void step(){
        index++;
        if (index == Integer.MAX_VALUE) {
            index = 0;
        }
        enemyImag = enemyImgs[index / 15 % enemyImgs.length];
    }
}
